package com.example.boot1;

import java.util.*;

public class StringDemo {
    public static void main(String[] args) {
        String[] str1 =
                new String[]{"b","k","c","yy","lg","ah","c","n",
                             "m","w","z","s","g","d","yy"};
        String[] str2 =
                new String[]{"o","k","c","yy","ag","ah","g","p",
                             "s","z","w","s","c","f","yy"};

        Set<String> s1 = dealString(str1);
        Set<String> s2 = dealString(str2);

        s1.retainAll(s2);

        Iterator<String> iterator = s1.iterator();
        while(iterator.hasNext()){
            String element = iterator.next();
            //输出的就是 取得的相同的元素
            System.out.print(element+"\t ");
        }
    }
    public static Set<String> dealString(String[] arr){
        Set<String> s =  new HashSet<>();
        List<String> list = Arrays.asList(arr);
        s.addAll(list);
        return s;
    }
}
